import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_exam_test_count.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/page/common/common_loading_dialog.dart';
import 'package:flutter_learn_vi/src/page/common/common_nodata_widget.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/23.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///考试规则
class ExamRulePage extends StatefulWidget {
  @override
  _ExamRulePageState createState() => _ExamRulePageState();
}

class _ExamRulePageState extends State<ExamRulePage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getExampCount();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("考试规则"),
      ),
      backgroundColor: Colors.white,

      ///填充布局
      body: Container(
          padding: EdgeInsets.all(20),
          width: double.infinity,
          height: double.infinity,
          child: SingleChildScrollView(
            child: buildColumn(),
          )),
    );
  }

  Widget buildColumn() {
    if (_isLoading) {
      return LoadingWidget();
    }
    if (_examTestCountConfigBean == null) {
      return NoDataWidget(
        text: "暂无考试规则",
      );
    }

    String testCountModel = "";
    if (_examTestCountConfigBean.testCountModel == "day") {
      testCountModel = "每天";
    } else if (_examTestCountConfigBean.testCountModel == "month") {
      testCountModel = "每月";
    } else {}

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          "${_examTestCountConfigBean.message}",
          style: TextStyle(color: Color(0xff333333), fontSize: 16),
        ),
        Text(
          "考试时间为 ${_examTestCountConfigBean.examTimeCount} 分钟",
          style: TextStyle(color: Color(0xff333333), fontSize: 16),
        ),
        SizedBox(
          height: 20,
        ),
        Text(
          "考试次数为 $testCountModel ${_examTestCountConfigBean.testCount} 次",
          style: TextStyle(color: Color(0xff333333), fontSize: 16),
        )
      ],
    );
  }

  bool _isLoading = true;
  ExamTestCountConfigBean _examTestCountConfigBean;

  ///获取考试规则 考试次数限制 考试
  Future<bool> getExampCount() async {
    Map<String, dynamic> map = Map();
    //post请求发送
    ResponseInfo responseInfo = await DioUtils.instance.postRequest(
      url: HttpHelper.exampRuleUrl,
      jsonMap: map,
    );
    if (responseInfo.success) {
      _examTestCountConfigBean =
          ExamTestCountConfigBean.fromMap(responseInfo.data);
    }
    _isLoading = false;
    if (mounted) {
      setState(() {});
    }

    return Future.value(true);
  }
}
